package com.ymttest.business.service.productdata.impl;

import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.business.service.productdata.bean.ApplyProductBean;
import com.ymttest.business.service.productdata.bean.ProductLivesBean;

public class NewLiveService extends AbstractLiveService{
	private ApplyProductBean applyProductBean;
	public NewLiveService(ApplyProductBean applyProductBean){
		this.applyProductBean = applyProductBean;
	}
	
	
	@Override
	protected ProductLivesBean doAddProductInLive(String productId) {
		ProductLivesBean productLivesBean = new ProductLivesBean();
		
		try{
			if (applyProductBean.getPreLiveCount()>0){
				List<Integer> liveIds = LiveCallService.createLivesInFuture(applyProductBean.getSellerId(),
						applyProductBean.getSellerName(),applyProductBean.getPreLiveCount(),3);
				
				productLivesBean.setPreLives(liveIds);
				this.addProductinLives(applyProductBean.getSellerId(), productId, liveIds);
				
				liveIds.forEach(x->{
					try {
						LiveCallService.closeLive(x, applyProductBean.getSellerId());
					} catch (Exception e) {
						e.printStackTrace();
					}
				});
			}
			
			
			
			if (applyProductBean.isHasNowLive()){
				List<Integer> liveIds = LiveCallService.createLivesInProcessAndInFuture(applyProductBean.getSellerId(),
						applyProductBean.getSellerName(),applyProductBean.getFutureLiveCount(),3);
				productLivesBean.setNowLive(liveIds.get(0));
				productLivesBean.setFutureLives(liveIds.subList(1, liveIds.size()));
				this.addProductinLives(applyProductBean.getSellerId(), productId, liveIds);
			
			
			}else{
				if (applyProductBean.getFutureLiveCount()>0){
					List<Integer> liveIds = LiveCallService.createLivesInFuture(applyProductBean.getSellerId(),
							applyProductBean.getSellerName(),applyProductBean.getFutureLiveCount(),3);
					
					productLivesBean.setFutureLives(liveIds);
					this.addProductinLives(applyProductBean.getSellerId(), productId, liveIds);
				}
			}
		}catch(Exception e){
			Logger.fail(e);
		}
		
		return productLivesBean;
	}

	
	
	


}
